<?php

add_theme_support( 'menus' );

add_theme_support( 'post-thumbnails' );

// FUNCTION TO RETURN THE CONTENT PAGE OR POST
function get_the_post()
{
    if ( have_posts() ) :
        while ( have_posts() ) : the_post();
            get_template_part( 'content-post' ); 
        endwhile;
    else :
        
    endif;
}

function get_post_by_id($id_post,$title="")
{
    $my_postid = $id_post;//This is page id or post id
    $content_post = get_post($my_postid);
   
    $content = $content_post->post_content;
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    
    $t=$content_post->post_title;
    $t = apply_filters('the_title', $t);
    $t = str_replace(']]>', ']]>', $t);
    
    switch ($title) {
        case 'sub-title':

                ?>
                <div class="sub-title">
                    <div class="line"></div>
                    <h2><?php echo $t; ?></h2>
                </div>
                <?php 
            break;

        default:
            break;
    }
    echo $content;
}

function the_excerpt_max_charlength($charlength) {
	$excerpt = get_the_excerpt();
	$charlength++;

	if ( mb_strlen( $excerpt ) > $charlength ) {
		$subex = mb_substr( $excerpt, 0, $charlength - 5 );
		$exwords = explode( ' ', $subex );
		$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
		if ( $excut < 0 ) {
			echo mb_substr( $subex, 0, $excut );
		} else {
			echo $subex;
		}
		echo '[...]';
	} else {
		echo $excerpt;
	}
}

// IF YOUR SITE IS MIANTENANCE STATUS
function wpr_maintenance_mode() {
    if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
        wp_die('Maintenance, please come back soon.');
    }
}
//add_action('get_header', 'wpr_maintenance_mode');

// REMOVE SHORTCOTS FROM DASHBOARD ADMIN PAINEL
function remove_dashboard_widgets() {
	global $wp_meta_boxes;

	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_drafts']);
	//unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);

}
add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );

// FUNCTION FOR ADD SHORTCODE FOR VIEW A PDF FILE IN PAGE
// EXAMPLE TO USE: [pdf href="http://yoursite.com/linktoyour/file.pdf"]View PDF[/pdf]
function pdflink($attr, $content) {
	return '<a class="pdf" href="http://docs.google.com/viewer?url=' . $attr['href'] . '">'.$content.'</a>';
}
add_shortcode('pdf', 'pdflink');

// ADD A FAVICON TO WORDPRESS HEAD
function childtheme_favicon() { ?>
	<link rel="shortcut icon" href="<?php echo bloginfo('stylesheet_directory') ?>/images/logo.ico" > 
<?php }
add_action('wp_head', 'childtheme_favicon');

//
function remove_footer_admin () {
    echo  bloginfo('name');
} 
add_filter('admin_footer_text', 'remove_footer_admin'); 

//
// EXAMPLE TO USE: [sub-title]Titulo[/sub-title]
function title_content($attr,$content) {
	return '<div class="sub-title"><div class="line"></div><h2>'.$content.'</h2></div>';
}
add_shortcode('sub-title', 'title_content');

// FUNCTION FOR ADD SHORTCODE FOR VIEW A PDF FILE IN PAGE
// EXAMPLE TO USE: [publicacao pdf="http://yoursite.com/linktoyour/file.pdf"][/publicacao]
function publicacaolink($attr, $content) {
	return '<a class="view" target="_blank" href="http://docs.google.com/viewer?url=' . $attr['pdf'] . '">ver</a>'
              .'<a class="pdf" href="' . $attr['pdf'] . '">download pdf</a>';
}
add_shortcode('publicacao', 'publicacaolink');

function kriesi_pagination($pages = '', $range = 2)
{  
     $showitems = ($range * 2)+1;  

     global $paged;
     if(empty($paged)) $paged = 1;

     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     }   

     if(1 != $pages)
     {
         echo "<div class='model-pagination'>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>";

         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
             }
         }

         if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a>";  
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
         echo "</div>\n";
     }
}